package ru.troyanov.Datchick.services;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.troyanov.Datchick.models.Measurement;
import ru.troyanov.Datchick.repositories.MeasurementRepositories;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class MeasurementService {
    private final MeasurementRepositories measurementRepositories;

    public MeasurementService(MeasurementRepositories measurementRepositories) {
        this.measurementRepositories = measurementRepositories;
    }

    public List<Measurement> findAll() {
        return measurementRepositories.findAll();
    }

    @Transactional
    public void save(Measurement measurement) {
        measurementRepositories.save(measurement);
    }

    public List<Measurement> findRainyDay(boolean rain) {
        return measurementRepositories.findAllByRain(rain);
    }
}
